﻿//判断是否ie 6,7,8
function isIe678() {
    $.browser.msie && ($.browser.version == '6.0' || $.browser.version == '7.0' || $.browser.version == '8.0')
}

if (!window.location.origin) {
    window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
}

if (String.prototype.startsWith == undefined) {
    String.prototype.startsWith = function () {
        if (typeof (arguments[0]) == 'string' && arguments[0] != '') {
            var sub_str = this.substr(0, arguments[0].length);
            return sub_str == arguments[0];
        } else {
            return false;
        }
    }
}

//提交post请求到url
function SubmitForm(data, url) {

    // 创建一个 form  
    var form1 = document.createElement("form");
    form1.id = "form1";
    form1.name = "form1";

    // 添加到 body 中  
    document.body.appendChild(form1);

    for (var field in data) {
        // 创建一个输入  
        var input = document.createElement("input");
        // 设置相应参数  
        input.type = "text";
        input.name = field;
        input.value = data[field];

        // 将该输入框插入到 form 中  
        form1.appendChild(input);

    }

    // form 的提交方式  
    form1.method = "POST";
    // form 提交路径  
    form1.action = url;

    // 对该 form 执行提交  
    form1.submit();
    // 删除该 form  
    document.body.removeChild(form1);
}

//jquery打印当前节点字符串
var oldOnload = window.onload;
if (typeof window.onload != 'function') {
    window.onload = function () {
        $.fn.extend({
            print: function () {
                if (this.size() != 0) {
                    var another = $(this[0]).clone();
                    return $("<div></div>").append(another).html();
                } else {
                    return "";
                }
            }
        })
    };
} else {
    window.onload = function () {
        oldOnload();
        $.fn.extend({
            print: function () {
                if (this.size() != 0) {
                    var another = $(this[0]).clone();
                    return $("<div></div>").append(another).html();
                } else {
                    return "";
                }
            }
        });
    }
}

//$.fn.extend({
//    print: function() {
//        if (this.size() != 0) {
//            var another = $(this[0]).clone();
//            return $("<div></div>").append(another).html();
//        } else {
//            return "";
//        }
//    }
//});

//字符串格式化输出
String.prototype.format = function () {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g,
        function (m, i) {
            return args[i];
        });
    }


